/*
**  Stata replication code for Table 1. This file reads 
**  the output created by the Gauss file MONTE.PRG.
**  December 22, 2001
**  Michael Tomz and Jason Wittenberg
*/

version 7.0
#delimit;

clear; 
infile v1biaskk v2biaskk v3biaskk 
       v1varkk v2varkk v3varkk v1msekk v2msekk v3msekk 
       v1biassur v2biassur v3biassur v1varsur v2varsur v3varsur 
       v1msesur v2msesur v3msesur v1 v2 v3 pld1sur pld2sur pld3sur 
       pld1kk pld2kk pld3kk pcwdkk1 pcwdkk2 pcwdkk3 
       pcwdsur1 pcwdsur2 pcwdsur3 competkk competsur pcpsur pcpkk 
       using monte.out;                     /* Read in data produced by MONTE.PRG */
       
for num 1/3: gen ldX=vX<4.99;
label var ld1 "Loses deposit?";                /* Party lost electoral deposit? */

gen cwd1=v1>v2 & v1>v3;                        /* Candidate wins district? */
gen cwd2=v2>v1 & v2>v3;
gen cwd3=v3>v2 & v3>v1;
label var cwd1 "Candidate wins district?";

gen compet=(v1>=30 & v1 <40) & (v2>=30 & v2 <40) &     /* District competitive? */
           (v3>=30 & v3 <40);
label var compet "District competitive?";
         
drop v2bias* v2var* v2mse*;                            /* Drop middle party */
         
gen mabkk_l=abs(v1biaskk);                             /* Mean absolute bias KK */
la var mabkk_l "Mean abs bias KK large party";
gen mabkk_s=abs(v3biaskk);
la var mabkk_s "Mean abs bias KK large party";

gen mabsur_l=abs(v1biassur);                           /* Mean absolute bias SUR */
la var mabsur_l "Mean abs bias SUR large party";
gen mabsur_s=abs(v3biassur);
la var mabsur_s "Mean abs bias SUR large party";

/* The code below displays the quantities from Table 1 */

noisily di "Mean Absolute Bias for KK";
noisily summ mabkk*;             
noisily di " ";

noisily di "Mean Absolute Bias for SUR";
noisily summ mabsur*;             
noisily di " ";

noisily di "Variance for KK";
noisily summ v?varkk;
noisily di " ";

noisily di "Variance for SUR";
noisily summ v?varsur;
noisily di " ";

noisily di "MSE for KK";
noisily summ v?msekk;
noisily di " ";

noisily di "MSE for SUR";
noisily summ v?msesur;
noisily di " ";

noisily di "Predict the district winner";
noisily summ pcp*;
noisily di " ";

rename compet ocompet;
noisily di "Identify competitive districts";
noisily summ compet* if ocompet==1;
noisily di " ";

replace competkk=1-competkk;
replace competsur=1-competsur;
noisily di "Identify uncompetitive districts";
noisily summ compet* if ocompet==0;
noisily di " ";

noisily di "Identify small parties that got <5%";
noisily summ pld3* if ld3==1;
noisily di " ";

replace pld3kk=1-pld3kk;
replace pld3sur=1-pld3sur;
noisily di "Identify small parties that got >5%";
noisily summ pld3* if ld3==0;
noisily di " ";
